package com.uidt.project.ptsj.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.uidt.common.utils.SecurityUtils;
import com.uidt.framework.aspectj.lang.annotation.Anonymous;
import com.uidt.framework.security.LoginUser;
import org.apache.catalina.security.SecurityUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.uidt.framework.aspectj.lang.annotation.Log;
import com.uidt.framework.aspectj.lang.enums.BusinessType;
import com.uidt.project.ptsj.domain.PtsjScreenArticle;
import com.uidt.project.ptsj.service.IPtsjScreenArticleService;
import com.uidt.framework.web.controller.BaseController;
import com.uidt.framework.web.domain.AjaxResult;
import com.uidt.common.utils.poi.ExcelUtil;
import com.uidt.framework.web.page.TableDataInfo;

/**
 * 大屏列内容，包括闭环管理、部门共治、行业自治、平台协同Controller
 * 
 * @author uidt
 * @date 2024-09-23
 */
@RestController
@RequestMapping("/ptsj/article")
public class PtsjScreenArticleController extends BaseController
{
    @Autowired
    private IPtsjScreenArticleService ptsjScreenArticleService;

    /**
     * 查询大屏列内容，包括闭环管理、部门共治、行业自治、平台协同列表，展示用（排序方式不同）
     */
    @Anonymous
//    @PreAuthorize("@ss.hasPermi('ptsj:article:list')")
    @GetMapping("/list")
    public TableDataInfo list(PtsjScreenArticle ptsjScreenArticle)
    {
        startPage();
        List<PtsjScreenArticle> list = ptsjScreenArticleService.selectPtsjScreenArticleList(ptsjScreenArticle);
        return getDataTable(list);
    }

    /**
     * 查询大屏列内容，包括闭环管理、部门共治、行业自治、平台协同列表，后台管理用（排序方式不同）
     */
    @Anonymous
    @GetMapping("/listForBack")
    public TableDataInfo listForBack(PtsjScreenArticle ptsjScreenArticle)
    {
        startPage();
        LoginUser user = SecurityUtils.getLoginUser();
        ptsjScreenArticle.setGxdwdm(user.getUser().getDept().getDeptcode().substring(0,12));
        ptsjScreenArticle.setOrderType("listForBack");
        List<PtsjScreenArticle> list = ptsjScreenArticleService.selectPtsjScreenArticleList(ptsjScreenArticle);
        return getDataTable(list);
    }

    /**
     * 导出大屏列内容，包括闭环管理、部门共治、行业自治、平台协同列表
     */
//    @PreAuthorize("@ss.hasPermi('ptsj:article:export')")
    @Log(title = "大屏列内容，包括闭环管理、部门共治、行业自治、平台协同", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PtsjScreenArticle ptsjScreenArticle)
    {
        List<PtsjScreenArticle> list = ptsjScreenArticleService.selectPtsjScreenArticleList(ptsjScreenArticle);
        ExcelUtil<PtsjScreenArticle> util = new ExcelUtil<PtsjScreenArticle>(PtsjScreenArticle.class);
        util.exportExcel(response, list, "大屏列内容，包括闭环管理、部门共治、行业自治、平台协同数据");
    }

    /**
     * 获取大屏列内容，包括闭环管理、部门共治、行业自治、平台协同详细信息
     */
//    @PreAuthorize("@ss.hasPermi('ptsj:article:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(ptsjScreenArticleService.selectPtsjScreenArticleById(id));
    }

    /**
     * 新增大屏列内容，包括闭环管理、部门共治、行业自治、平台协同
     */
//    @PreAuthorize("@ss.hasPermi('ptsj:article:add')")
    @Log(title = "大屏列内容，包括闭环管理、部门共治、行业自治、平台协同", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PtsjScreenArticle ptsjScreenArticle)
    {
        ptsjScreenArticle.setCreateTime(new Date());
        LoginUser user = SecurityUtils.getLoginUser();
        ptsjScreenArticle.setGxdwdm(user.getUser().getDept().getDeptcode());
        ptsjScreenArticle.setGxdwmc(user.getUser().getDept().getDeptName());
        return toAjax(ptsjScreenArticleService.insertPtsjScreenArticle(ptsjScreenArticle));
    }

    /**
     * 修改大屏列内容，包括闭环管理、部门共治、行业自治、平台协同
     */
//    @PreAuthorize("@ss.hasPermi('ptsj:article:edit')")
    @Log(title = "大屏列内容，包括闭环管理、部门共治、行业自治、平台协同", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PtsjScreenArticle ptsjScreenArticle)
    {
        return toAjax(ptsjScreenArticleService.updatePtsjScreenArticle(ptsjScreenArticle));
    }

    /**
     * 删除大屏列内容，包括闭环管理、部门共治、行业自治、平台协同
     */
//    @PreAuthorize("@ss.hasPermi('ptsj:article:remove')")
    @Log(title = "大屏列内容，包括闭环管理、部门共治、行业自治、平台协同", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(ptsjScreenArticleService.deletePtsjScreenArticleByIds(ids));
    }
    /**
     * 置顶不置顶
     */

    @PostMapping("/changeTop")
    public AjaxResult changeTop(@RequestBody PtsjScreenArticle ptsjScreenArticle)
    {
        return toAjax(ptsjScreenArticleService.changeTop(ptsjScreenArticle));
    }

    /**
     * 有效无效修改
     */

    @PostMapping("/changeDel")
    public AjaxResult changeDel(@RequestBody PtsjScreenArticle ptsjScreenArticle)
    {
        return toAjax(ptsjScreenArticleService.changeTop(ptsjScreenArticle));
    }
}
